package com.example.administrator.musicplayer.bean;


import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.administrator.musicplayer.R;

import java.util.ArrayList;

//import com.example.administrator.musicplayer.R;

public class MusicAdapter extends ArrayAdapter<Music> {
    private int recourseId;
    public MusicAdapter(Context context, int textViewResourceId, ArrayList<com.example.administrator.musicplayer.bean.Music> objects)
    {
        super(context,textViewResourceId,objects);
        recourseId = textViewResourceId;

    }


    @Override
    public View getView(int position, View convertView, ViewGroup parent)
    {
        Music music = getItem(position);
        View view;
        ViewHolder viewHolder;
        if(convertView==null)
        {
            view = LayoutInflater.from(getContext()).inflate(recourseId,null);
            viewHolder= new ViewHolder();
            viewHolder.imageView = (ImageView)view.findViewById(R.id.btn_img);
            viewHolder.author =  (TextView)view.findViewById(R.id.author);
            viewHolder.musicName = (TextView)view.findViewById(R.id.music_name);
            viewHolder.musicDuring = (TextView)view.findViewById(R.id.music_during);
            view.setTag(viewHolder);
        }else{
            view = convertView;
            viewHolder = (ViewHolder)view.getTag();
        }
//        view = LayoutInflater.from(getContext()).inflate(recourseId,null);
//        TextView musicName = (TextView)view.findViewById(R.id.music_name);
//        TextView musicDuring = (TextView)view.findViewById(R.id.music_during);
        viewHolder.musicName.setText(music.getName());
        viewHolder.musicDuring.setText("时长:"+music.getDuration());
//        viewHolder.author = (TextView)view.findViewById(R.id.author);
        viewHolder.author.setText(music.getSinger());
        return view;
    }

    class ViewHolder{
        TextView musicName;
        TextView musicDuring;
        TextView author;
        ImageView imageView;
    }

}
